package com.yanqu.road.server.manager.activity.sonhai.handler.impl;

import com.yanqu.road.entity.activity.sonhai.config.SonHaiEventConfig;
import com.yanqu.road.entity.activity.sonhai.data.SonHaiPlotData;
import com.yanqu.road.entity.activity.sonhai.data.SonHaiRegionData;
import com.yanqu.road.entity.activity.sonhai.param.SonHaiCreatePlotResp;
import com.yanqu.road.entity.activity.sonhai.param.SonHaiWinPlotResp;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiActivity;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiTeam;
import com.yanqu.road.server.manager.activity.sonhai.CrossSonHaiUser;
import com.yanqu.road.server.manager.activity.sonhai.handler.IPlotTypeHandler;
import com.yanqu.road.server.manager.activity.sonhai.handler.entity.PlotTypeHandlerExploreReq;
import com.yanqu.road.server.manager.activity.sonhai.handler.entity.PlotTypeHandlerExploreResp;

import java.util.List;

/**
 * 鹊山
 */
public class PlotType9Handler implements IPlotTypeHandler {

    /**
     * 探索后处理-随机探明周边X格范围内的Y个地块
     * @param req
     * @return
     */
    @Override
    public PlotTypeHandlerExploreResp explore(PlotTypeHandlerExploreReq req) {
        CrossSonHaiUser user = req.getUser();
        SonHaiRegionData regionData = user.getRegionData();
        CrossSonHaiActivity activity = req.getActivity();
        CrossSonHaiTeam team = activity.getTeam(user.getTeamId());
        SonHaiPlotData plotData = req.getPlotData();
        SonHaiEventConfig eventConfig = activity.getSonHaiConfig().getEventConfig(plotData.getPlotId());
        //原寻踪进度
        int oldProgress = regionData.getProgress();
        //直接镇伏该地块
        SonHaiWinPlotResp winPlotResp = user.winPlot(plotData);
        //获得积分
        long addScore = user.addScoreByPlot(regionData, plotData, oldProgress);
        winPlotResp.setAddScore(addScore);
        //添加山海灵气
        long baseAddAuraScore = winPlotResp.getAddAuraScore();
        int auraScoreOpRate = user.getAuraScoreOpRate(plotData, true);//buff:山海灵气加成率
        long auraScoreOpValue = user.getAuraScoreOpValue(plotData, true);//buff:山海灵气加成值
        long addAuraScore = user.countAureScore(baseAddAuraScore, auraScoreOpRate, auraScoreOpValue);
        if (addAuraScore > 0) {
            team.changeAuraScore(user, addAuraScore);
        }
        winPlotResp.setAddAuraScore(addAuraScore);
        //效果处理
        int range = eventConfig.getParamList().get(0);//读配置，range范围内
        int num = eventConfig.getParamList().get(1);//读配置，num个地块
        //随机生成地块
        List<SonHaiCreatePlotResp> plotDataList = activity.randomCreatePlot(user, regionData, plotData, range, num, false);
        //返回
        PlotTypeHandlerExploreResp resp = new PlotTypeHandlerExploreResp();
        resp.setNewPlotDataList(plotDataList);
        resp.setWinPlotResp(winPlotResp);
        return resp;
    }
}
